package com.example.hdwx.myapplication.json;

import android.util.Log;

import com.example.hdwx.myapplication.eneity.Cooklist_enetity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hudongwx on 17-2-15.
 */

public class Cooklist_Json {

//    public static Date getNowDate(String ReleaseDate){
//        Date date = new Date(ReleaseDate);
//        SimpleDateFormat format = new SimpleDateFormat("MM-dd");
//        String timedata = format.format(date);
//        ParsePosition parsePosition = new ParsePosition(8);
//        Date date1 = format.parse(timedata, parsePosition);
//        return date1;
//    }

    public static List<Cooklist_enetity> cooklist_json(String str){
        List<Cooklist_enetity>list=new ArrayList();
        try {
            JSONObject obj=new JSONObject(str);
            JSONArray array=obj.getJSONArray("data");
            for (int i = 0; i <array.length() ; i++) {
                Cooklist_enetity dc=new Cooklist_enetity();
                JSONObject obj1=array.getJSONObject(i);
                dc.setId(obj1.optString("id"));
                dc.setTitle(obj1.optString("title"));
                dc.setDetailsUrl(obj1.optString("detailsUrl"));
                dc.setImageUrl(obj1.optString("imageUrl"));
                dc.setClickCount(obj1.optString("clickCount"));
                dc.setShareCount(obj1.optString("shareCount"));
                dc.setMaketime(obj1.optString("maketime"));
                dc.setDescription(obj1.optString("description"));
                //转化时间格式
                dc.setReleaseDate((obj1.optString("releaseDate")));
                Log.e("Cooklist_json",dc.getId());
                list.add(dc);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}
